var chosenMarket = '';
var chosenVehicle = 0;
var chosenVehicleBrand = 0;
var chosenVehicleModel = 0;
var chosenVehicleEngine = 0;
var chosenVehicleType = 0;
var chosenVehicleFilter = 0;

var vehicleBrandResponse;
var vehicleModelResponse;
var vehicleEngineResponse;
var vehicleTypeResponse;
var vehicleFilterResponse;

var backFromFilterSite = false;

var replacementsList;

$(document).on('pagebeforeshow', function(e) {
    if (e.handled !== true) {
        var target = e.currentTarget.URL;
        pageLoadHandler(target);
        e.handled = true;
    }
});

$(document).ready(function() {

	$(document).on('click', '#chosenMarketWidget', function() {
		if (chosenMarket == 'wix') {
			return $.mobile.changePage('catalog_eu.html', {
				transition: 'slide'
			});
		} else {
			return $.mobile.changePage('catalog_us.html', {
				transition: 'slide'
			});
		}
	});

	// zamienniki
	$(document).on('click', '#replacement_submit_r', function() {

		$.ajax({
			url: "http://m.wixeurope.com/m/Ajax/ReplacementFilterList.aspx?value="+ $('#replacement_input_r').val() +"&languageName=polish",
			type: "GET",
			dataType: "json",
			beforeSend: function() {
				$.mobile.loading('show', {text: 'Ładowanie'});
			},
			success: function(data) {
				replacementsList = data.bindings;
				$.mobile.loading('hide');
				return $.mobile.changePage('replacements_filter.html', {
					transition: 'slide'
				});
			}
		});

	});

	// multiwyszukiwarka
	$(document).on('click', '#replacement_submit_multisearch', function() {

		$.ajax({
			url: "http://m.wixeurope.com/m/Ajax/MultisearchReplacementFilterList.aspx?value="+ $('#replacement_input_multisearch').val() +"&languageName=polish",
			type: "GET",
			dataType: "json",
			beforeSend: function() {
				$.mobile.loading('show', {text: 'Ładowanie'});
			},
			success: function(data) {
				replacementsList = data.bindings;
				console.log(data.bindings[0]['com']);
				if (data.bindings[0]['com'] == 'queryTooShort') {
					alert('Zapytanie jest zbyt krótkie');
					$.mobile.loading('hide');
					return;
				}
				if (data.bindings[0]['com'] == 'queryTooLong') {
					alert('Zapytanie jest zbyt długie');
					$.mobile.loading('hide');
					return;
				}
				$.mobile.loading('hide');
				return $.mobile.changePage('replacements_filter.html', {
					transition: 'slide'
				});
			}
		});

	});

});

var pageLoadHandler = function(target) {
	// wybór typu pojazdu - baza europejska
	if (target.indexOf('catalog_eu') > -1) {vehicleTypePageLoad('filtron')}

	// wybór typu pojazdu - baza amerykańska
	if (target.indexOf('catalog_us') > -1) {vehicleTypePageLoad('wix')}

	// wybór marki, modelu, silnika i filtra
	if (target.indexOf('passenger_eu') > -1) {catalogPageLoad('filtron', 2)};
	if (target.indexOf('trucks_eu') > -1) {catalogPageLoad('filtron', 3)};
	if (target.indexOf('machines_eu') > -1) {catalogPageLoad('wix', 6)};
	if (target.indexOf('passenger_us') > -1) {catalogPageLoad('wix', 7)};
	if (target.indexOf('trucks_us') > -1) {catalogPageLoad('wix', 8)};
	if (target.indexOf('machines_us') > -1) {catalogPageLoad('wix', 6)};

	// wyświetlenia filtra
	if (target.indexOf('filtron_filter') > -1) {filtronFilterPageLoad()};
	if (target.indexOf('wix_filter') > -1) {wixFilterPageLoad()};
	if (target.indexOf('replacements_filter') > -1) {replacementsFilterPageLoad()};

	if (
		(target.indexOf('catalog_eu') == -1) &&
		(target.indexOf('catalog_us') == -1) &&
		(target.indexOf('passenger_eu') == -1) &&
		(target.indexOf('trucks_eu') == -1) &&
		(target.indexOf('machines_eu') == -1) &&
		(target.indexOf('passenger_us') == -1) &&
		(target.indexOf('trucks_us') == -1) &&
		(target.indexOf('machines_us') == -1) &&
		(target.indexOf('filtron_filter') == -1) &&
		(target.indexOf('wix_filter') == -1) &&
		(target.indexOf('replacements_filter') == -1) &&
		(target.indexOf('replacements') == -1)
	) 
	{
		$('#pageBanner').attr('src', 'images/baner.jpg');
		$('#chosenMarketWidget').fadeOut('fast');
	} else {
		$('#pageBanner').attr('src', 'images/baner_clean.jpg');
		$('#chosenMarketWidget').fadeIn('fast');
	}

	//changeMarketWidget
	if (chosenMarket == 'wix') {
		$('#display_current_market').html('US');
	} else {
		$('#display_current_market').html('EU');
	}

};

var vehicleTypePageLoad = function(market) {
	chosenMarket = market;
};

var catalogPageLoad = function(market, vehicle) {
	chosenMarket = market;
	chosenVehicle = vehicle;

	var brandBox = $('#brand_box'), 
	modelBox = $('#model_box'), 
	engineBox = $('#engine_box'), 
	filterTypeBox = $('#filter_type_box'),
	filterBox = $('#filter_box');

	var brandDropdown = $('#brand_tab_dropdown'),
	modelDropdown = $('#model_tab_dropdown'),
	filterTypeDropdown = $('#filter_type_tab_dropdown'),
	filterDropdown = $('#filter_tab_dropdown');

	var engineSelectable = $('table.enginesTable tbody tr');
	var engineTBody = $('table.enginesTable tbody');

	// ukrywanie dropdownów
	if (!backFromFilterSite) {
		$(modelBox).hide(); $(engineBox).hide(); $(filterBox).hide(); $(filterTypeBox).hide();

		// wypełnienie pierwszego dropdowna
		$.ajax({
				url: "http://m.wixeurope.com/m/MobileAjax/getBrandsAjax.aspx?market=" + chosenMarket + "&vehicleId=" + chosenVehicle + "&languageName=polish",
				data: "GET",
				dataType: "json",
				beforeSend: function() {
					$.mobile.loading('show', {text: 'Ładowanie'});
					clearDropdown(brandDropdown);
				},
				success: function(data) {
					if (data.length > 0) {
						vehicleBrandResponse = data;
						$(data).each(function(i, el) {
							$(brandDropdown).append($('<option></option>').html(el.Name).val(el.Id));
						});
					} else {
						alert("Błąd połączenia z bazą danych.");
					}
					$.mobile.loading('hide');
				}
			});

	} else {

		$(vehicleBrandResponse).each(function(i, el) {
			$('#brand_tab_dropdown').append($('<option></option>').html(el.Name).val(el.Id));
		});
		$('#brand_tab_dropdown').val(chosenVehicleBrand);

		$(vehicleModelResponse).each(function(i, el) {
			$('#model_tab_dropdown').append($('<option></option>').html(el.Name).val(el.Id));
		});
		$('#model_tab_dropdown').val(chosenVehicleModel);
		$(modelBox).show();

		$('table.enginesTable tbody tr').remove();
		$(vehicleEngineResponse).each(function(i, el) {
			$('table.enginesTable tbody').append(appendEngineTableRow(el));
		});
		$('#engine-id-' + chosenVehicleEngine).css('font-weight', 'bold');
		$(engineBox).show();

		$('#filter_type_tab_dropdown option').remove();
		$(vehicleTypeResponse).each(function(i, el) {
			$('#filter_type_tab_dropdown').append($('<option></option>').html(el.Name).val(el.Id));
		});	
		$('#filter_type_tab_dropdown').val(chosenVehicleType);
		$(filterTypeBox).show();

		$('#filter_tab_dropdown option').remove();
		$(vehicleFilterResponse).each(function(i, el) {
			$('#filter_tab_dropdown').append($('<option></option>').html(el.Name).val(el.Id));
		});
		$(filterBox).show();
		scrollScreenToBottom();

		backFromFilterSite = false;


	}

	$(brandDropdown).on('change', function() {
		if ($(brandDropdown).val() > 0) {
			$.ajax({
				url: "http://m.wixeurope.com/m/MobileAjax/getModelsAjax.aspx?market=" + chosenMarket + "&brandId=" + $(brandDropdown).val() + "&languageName=polish",
				type: "GET",
				dataType: "json",
				beforeSend: function() {
					$.mobile.loading('show', {text: 'Ładowanie'});
					chosenVehicleBrand = $(brandDropdown).val();
					clearDropdown(modelDropdown);
					$(engineBox).fadeOut('fast');
					$(filterTypeBox).fadeOut('fast', function() {clearDropdown(filterTypeDropdown)});
					$(filterBox).fadeOut('fast', function() {clearDropdown(filterDropdown)});
				},
				success: function(data) {
					if (data.length > 0) {
						vehicleModelResponse = data;
						$(data).each(function(i, el) {
							$(modelDropdown).append($('<option></option>').html(el.Name).val(el.Id));
						});
					} else {
						alert("Błąd połączenia z bazą danych.");
					}
					$(modelBox).fadeIn('fast', function() {
						scrollScreenToBottom();
					});
					$.mobile.loading('hide');
				}
			});
		}
	});

	$(modelDropdown).on('change', function() {
		$.ajax({
			url: "http://m.wixeurope.com/m/MobileAjax/getEnginesAjax.aspx?market=" + chosenMarket + "&modelId=" + $(modelDropdown).val() + "&languageName=polish",
			type: "GET",
			dataType: "json",
			beforeSend: function() {
				$.mobile.loading('show', {text: 'Ładowanie'});
				chosenVehicleModel = $(modelDropdown).val();
				$(filterTypeBox).fadeOut('fast', function() {clearDropdown(filterTypeDropdown)});
				$(filterBox).fadeOut('fast', function() {clearDropdown(filterDropdown)});
			},
			success: function(data) {
				$('table.enginesTable tbody tr').remove();
				if (data.length > 0) {
					vehicleEngineResponse = data;
					$(data).each(function(i, el) {
						$(engineTBody).append(appendEngineTableRow(el));
					});
				} else {
					alert("Błąd połączenia z bazą danych.");
				}

				$(engineBox).fadeIn('fast', function() {
					scrollScreenToBottom();
				});
				$.mobile.loading('hide');
			}
		});
	});

	$(document).on('click', 'table.enginesTable tbody tr', function() {
		var clickedTrId = $(this).attr('id');
		$('table.enginesTable tbody tr').each(function(i, el) {
			$(this).css('font-weight', 'normal');
		});

		chosenVehicleEngine = parseInt(clickedTrId.replace('engine-id-', ''));
		$.ajax({
			url: "http://m.wixeurope.com/m/MobileAjax/getTypesAjax.aspx?market=" + chosenMarket + "&modelId=" + $(modelDropdown).val() + "&engineId=" + chosenVehicleEngine + "&languageName=polish",
			type: "GET",
			dataType: "json",
			beforeSend: function() {
				$.mobile.loading('show', {text: 'Ładowanie'});
				clearDropdown(filterTypeDropdown);
				$(filterBox).fadeOut('fast', function() {clearDropdown(filterDropdown)});
			},
			success: function(data) {
				if (data.length > 0) {
					vehicleTypeResponse = data;
					$(data).each(function(i, el) {
						$(filterTypeDropdown).append($('<option></option>').html(el.Name).val(el.Id));
					});
				} else {
					alert("Błąd połączenia z bazą danych.");
				}
				$(filterTypeBox).fadeIn('fast', function() {
					scrollScreenToBottom();
				});
				$('#' + clickedTrId).css('font-weight', 'bold');
				$.mobile.loading('hide');
			}
		});
	});

	$(filterTypeDropdown).on('change', function() {
		chosenVehicleType = $(this).val();
		$.ajax({
			url: "http://m.wixeurope.com/m/MobileAjax/getFiltersAjax.aspx?market=" + chosenMarket + "&modelId=" + $(modelDropdown).val() + "&engineId=" + chosenVehicleEngine + "&filterTypeId=" + $(filterTypeDropdown).val() + "&languageName=polish",
			type: "GET",
			dataType: "json",
			beforeSend: function() {
				$.mobile.loading('show', {text: 'Ładowanie'});
				clearDropdown(filterDropdown);
			},
			success: function(data) {
				if (data.length > 0) {
					vehicleFilterResponse = data;
					$(data).each(function(i, el) {
						$(filterDropdown).append($('<option></option>').html(el.Name).val(el.Id));
					});
				} else {
					alert("Błąd połączenia z bazą danych.");
				}
				$(filterBox).fadeIn('fast', function() {
					scrollScreenToBottom();
				});
				$.mobile.loading('hide');
			}
		});

	});

	$(filterDropdown).on('change', function() {
		chosenVehicleFilter = $(filterDropdown).val();
		if (chosenMarket == 'filtron') return $.mobile.changePage('filtron_filter.html', {transition: 'slide'});
		if (chosenMarket == 'wix') return $.mobile.changePage('wix_filter.html', {transition: 'slide'});
	});
};

var filtronFilterPageLoad = function() {
	backFromFilterSite = true;
	if (chosenVehicleFilter != 0) {
		
		$.ajax({
			url: "http://m.wixeurope.com/m/MobileAjax/getFilterAjax.aspx?market=" + chosenMarket + "&filterId=" + chosenVehicleFilter + "&languageName=polish",
			type: "GET",
			dataType: "json",
			beforeSend: function() {
				$.mobile.loading('show', {text: 'Ładowanie'});
			},
			success: function(filterObject) {
				if (filterObject) {
					$('#t_filter').html(filterObject.t_Filter);
					$('#t_filter_number').html(filterObject.Number);
					$('#t_dimension').html(filterObject.t_Sizes + ":");
					$('#t_dim_a').html(filterObject.DimA);
					$('#t_dim_b').html(filterObject.DimB);
					$('#t_dim_c').html(filterObject.DimC);
					$('#t_dim_d').html(filterObject.DimD);
					$('#t_dim_e').html(filterObject.DimE);
					$('#t_dim_f').html(filterObject.DimF);
					$('#t_dim_g').html(filterObject.DimG);
					$('#t_dim_h').html(filterObject.DimH);
					$('#t_by_pass_valve').html(filterObject.t_ByPassValve);
					$('#t_anti_drain_valve').html(filterObject.t_AntiDrainValve);
					$('#t_anti_syphon_valve').html(filterObject.t_AntiSiphonValve);

					if (filterObject.ByPassValve) {
						$('#t_by_pass_valve_value').html(filterObject.t_Yes);
					} else {
						$('#t_by_pass_valve_value').html(filterObject.t_No);
					}

					if (filterObject.AntiDrainValve) {
						$('#t_anti_drain_valve_value').html(filterObject.t_Yes);
					} else {
						$('#t_anti_drain_valve_value').html(filterObject.t_No);
					}

					if (filterObject.AntiSiphonValve) {
						$('#t_anti_syphon_valve_value').html(filterObject.t_Yes);
					} else {
						$('#t_anti_syphon_valve_value').html(filterObject.t_No);
					}
					
					$('#t_applications').html(filterObject.t_PrincipleApplications);
					$('#t_applications_value').html(filterObject.PrincipleApplications);

					$('.largeFilterImage').attr('href', filterObject.largeImageUrl);
					$('#smallFilterImage').hide('fast', function() {
						$('#smallFilterImage').attr('src', filterObject.imageUrl);
						$('#smallFilterImage').fadeIn('slow');
					});
					

					$('#t_zoom').html(filterObject.t_Zoom);
					$('.filter_content').fadeIn('fast');
					$.mobile.loading('hide');
				}
			}
		});

	} else {
		return $.mobile.changePage('/', {
			transition: 'slide'
		});
	}
};

var wixFilterPageLoad = function() {
	backFromFilterSite = true;
	if (chosenVehicleFilter != 0) {
		
		$.ajax({
			url: "http://m.wixeurope.com/m/MobileAjax/getFilterAjax.aspx?market=" + chosenMarket + "&filterId=" + chosenVehicleFilter + "&languageName=polish",
			type: "GET",
			dataType: "json",
			beforeSend: function() {
				$.mobile.loading('show', {text: 'Ładowanie'});
			},
			success: function(filterObject) {
				$('#t_filter').html(filterObject.t_Filter);
				$('#t_filter_number').html(filterObject.Number);
				$('#t_dimension').html(filterObject.t_Sizes + " (mm):");
				$('#t_outside_dia_top').html(filterObject.t_OutsideDiaTop);
				$('#outside_dia_top').html(filterObject.OutsideDiaTop);
				$('#t_outside_dia_bottom').html(filterObject.t_OutsideDiaBottom);
				$('#outside_dia_bottom').html(filterObject.OutsideDiaBottom);
				$('#t_inside_dia_top').html(filterObject.t_InsideDiaTop);
				$('#inside_dia_top').html(filterObject.InsideDiaTop);
				$('#t_height').html(filterObject.t_Height);
				$('#filter_height').html(filterObject.Height);
				$('#t_thread_size').html(filterObject.t_ThreadSize);
				$('#filter_thread_size').html(filterObject.ThreadSize);

				$('#t_filter_style').html(filterObject.t_FilterStyle);
				$('#filter_style').html(filterObject.FilterStyle);
				$('#t_filter_type').html(filterObject.t_FilterType);
				$('#filter_type').html(filterObject.FilterType);
				$('#t_filter_media').html(filterObject.t_FilterMedia);
				$('#filter_media').html(filterObject.FilterMedia);
				$('#t_filter_service').html(filterObject.t_FilterService)
				$('#filter_service').html(filterObject.FilterService)

				$('#t_applications').html(filterObject.t_PrincipleApplications + ':');
				$('#t_applications_value').html(filterObject.PrincipleApplications);

				$('.largeFilterImage').attr('href', filterObject.largeImageUrl);
				$('#smallFilterImage').hide('fast', function() {
					$('#smallFilterImage').attr('src', filterObject.imageUrl);
					$('#smallFilterImage').fadeIn('slow');
				});

				$('#t_zoom').html(filterObject.t_Zoom);
				$('.filter_content').fadeIn('fast');
				$.mobile.loading('hide');
			}
		});

	} else {
		return $.mobile.changePage('/', {
			transition: 'slide'
		});
	}
};

var replacementsFilterPageLoad = function() {

	// replacements_tab_dropdown
	if (replacementsList != null) {
		$('#replacements_tab_dropdown').append($('<option selected="selected"></option>').val(-1).html('--- wybierz filtr ---'));
		$(replacementsList).each(function(i, el) {
			var manufacturer = el['Producent'] || el['Manufacturer'];
			var partNumber = el['Filtr obcy'] || el['Part number'];
			var replacement = el['Zamiennik'] || el['WIX Filter'];
			$('#replacements_tab_dropdown').append($('<option></option>').val(el.repFilterProd + ',' + el.repId).html(partNumber + ' ('+ manufacturer +') - ' + replacement));
		});
		if (replacementsList.length == 1) {
			console.log('1');
			$('#replacements_tab_dropdown option').each(function(i, el) {
				if ($(el).val() != -1) {
					$('#replacements_tab_dropdown').val($(el).val());
					setTimeout(function() {
						$('#replacements_tab_dropdown').change();
					}, 500);
				}
			});
		}
	} else {
		return $.mobile.changePage('/', {
			transition: 'slide'
		});
	}

	$(document).on('change', '#replacements_tab_dropdown', function() {
		var thisValue = $(this).val();
		if (thisValue != '-1') {
			var replacementMarket = thisValue.split(',');
			if (replacementMarket[0] == 'W') {

				$.ajax({
					url: "http://m.wixeurope.com/m/MobileAjax/getFilterAjax.aspx?market=wix&filterId=" + replacementMarket[1] + "&languageName=polish",
					type: "GET",
					dataType: "json",
					beforeSend: function() {
						$.mobile.loading('show', {text: 'Ładowanie'});
					},
					success: function(filterObject) {
						$('.filter_content').html('').append(wixFilterContent());

						$('#t_filter').html(filterObject.t_Filter);
						$('#t_filter_number').html(filterObject.Number);
						$('#t_dimension').html(filterObject.t_Sizes + " (mm):");
						$('#t_outside_dia_top').html(filterObject.t_OutsideDiaTop);
						$('#outside_dia_top').html(filterObject.OutsideDiaTop);
						$('#t_outside_dia_bottom').html(filterObject.t_OutsideDiaBottom);
						$('#outside_dia_bottom').html(filterObject.OutsideDiaBottom);
						$('#t_inside_dia_top').html(filterObject.t_InsideDiaTop);
						$('#inside_dia_top').html(filterObject.InsideDiaTop);
						$('#t_height').html(filterObject.t_Height);
						$('#filter_height').html(filterObject.Height);
						$('#t_thread_size').html(filterObject.t_ThreadSize);
						$('#filter_thread_size').html(filterObject.ThreadSize);

						$('#t_filter_style').html(filterObject.t_FilterStyle);
						$('#filter_style').html(filterObject.FilterStyle);
						$('#t_filter_type').html(filterObject.t_FilterType);
						$('#filter_type').html(filterObject.FilterType);
						$('#t_filter_media').html(filterObject.t_FilterMedia);
						$('#filter_media').html(filterObject.FilterMedia);
						$('#t_filter_service').html(filterObject.t_FilterService)
						$('#filter_service').html(filterObject.FilterService)

						$('#t_applications').html(filterObject.t_PrincipleApplications + ':');
						$('#t_applications_value').html(filterObject.PrincipleApplications);

						$('.largeFilterImage').attr('href', filterObject.largeImageUrl);
						$('#smallFilterImage').hide('fast', function() {
							$('#smallFilterImage').attr('src', filterObject.imageUrl);
							$('#smallFilterImage').fadeIn('slow');
						});

						$('#t_zoom').html(filterObject.t_Zoom);
						$('.filter_content').fadeIn('fast', function() {
							$.mobile.loading('hide');
						});
						
					}
				});

			}
			if (replacementMarket[0] == 'F') {

				$.ajax({
					url: "http://m.wixeurope.com/m/MobileAjax/getFilterAjax.aspx?market=filtron&filterId=" + replacementMarket[1] + "&languageName=polish",
					type: "GET",
					dataType: "json",
					beforeSend: function() {
						$.mobile.loading('show', {text: 'Ładowanie'});
					},
					success: function(filterObject) {
						if (filterObject) {

							$('.filter_content').html('').append(filtronFilterContent());

							$('#t_filter').html(filterObject.t_Filter);
							$('#t_filter_number').html(filterObject.Number);
							$('#t_dimension').html(filterObject.t_Sizes + ":");
							$('#t_dim_a').html(filterObject.DimA);
							$('#t_dim_b').html(filterObject.DimB);
							$('#t_dim_c').html(filterObject.DimC);
							$('#t_dim_d').html(filterObject.DimD);
							$('#t_dim_e').html(filterObject.DimE);
							$('#t_dim_f').html(filterObject.DimF);
							$('#t_dim_g').html(filterObject.DimG);
							$('#t_dim_h').html(filterObject.DimH);
							$('#t_by_pass_valve').html(filterObject.t_ByPassValve);
							$('#t_anti_drain_valve').html(filterObject.t_AntiDrainValve);
							$('#t_anti_syphon_valve').html(filterObject.t_AntiSiphonValve);

							if (filterObject.ByPassValve) {
								$('#t_by_pass_valve_value').html(filterObject.t_Yes);
							} else {
								$('#t_by_pass_valve_value').html(filterObject.t_No);
							}

							if (filterObject.AntiDrainValve) {
								$('#t_anti_drain_valve_value').html(filterObject.t_Yes);
							} else {
								$('#t_anti_drain_valve_value').html(filterObject.t_No);
							}

							if (filterObject.AntiSiphonValve) {
								$('#t_anti_syphon_valve_value').html(filterObject.t_Yes);
							} else {
								$('#t_anti_syphon_valve_value').html(filterObject.t_No);
							}
							
							$('#t_applications').html(filterObject.t_PrincipleApplications);
							$('#t_applications_value').html(filterObject.PrincipleApplications);

							$('.largeFilterImage').attr('href', filterObject.largeImageUrl);
							$('#smallFilterImage').hide('fast', function() {
								$('#smallFilterImage').attr('src', filterObject.imageUrl);
								$('#smallFilterImage').fadeIn('slow');
							});
							

							$('#t_zoom').html(filterObject.t_Zoom);
							$('.filter_content').fadeIn('fast', function() {
								$.mobile.loading('hide');
							});
						}
					}
				});

			}
		}
	});


};

var appendEngineTableRow = function(obj) {
	if (obj) {
		return '<tr id="engine-id-' + obj.Id + '"><td class="textAlignLeft">' + obj.Name + '</td><td>' + obj.CubicCapacity + '</td><td>' + obj.Code + '</td><td>' + obj.HorsePower + '</td></tr>';
	} 
	return "";
};

var replaceDamagedCharacters = function(data) {
	return data.replace('&#203;', 'Ë').replace('&#321;', 'Ł');
};

var clearDropdown = function(dropdown) {
	if (dropdown) {
		$(dropdown).find('option').each(function(i, el) {
			$(el).remove();
		});
	}
};

var clearDropdownExceptNegativeValue = function(dropdown) {
	if (dropdown) {
		$(dropdown).find('option').each(function(i, el) {
			if ($(el).val() != '-1') {
				$(el).remove();
			}
		});
	}
};

var scrollScreenToBottom = function() {
	$("html, body").animate({ scrollTop: $(document).height() }, 1000);
};

var wixFilterContent = function() {
	return '<div class="filter_title"><span id="t_filter"></span> <span id="t_filter_number" class="orage"></span></div><div class="filter_dotted">.........................................</div><div class="filter_image_cnt" style="float: right; margin-right: 0px !important;"><div class="filter_image"><a class="largeFilterImage" href="" rel="lightbox" title=""><img id="smallFilterImage" src=""/></a></div><a href="" rel="lightbox" id="t_zoom" class="largeFilterImage filter_zoom"></a></div><div id="t_dimension" class="filter_dimensions_title"></div><div style="float: left; width: 50%;"><div class="filter_dimensions_line" style="float: left; width: auto !important;"><div style="width: 100%" class="filter_dimensions_first_part"><span id="t_outside_dia_top"></span>: <span id="outside_dia_top" class="orage"></span></div><div style="width: 100%"class="filter_dimensions_part"><span id="t_outside_dia_bottom"></span>: <span id="outside_dia_bottom" class="orage"></span></div><div style="width: 100%" class="filter_dimensions_part"><span id="t_inside_dia_top"></span>: <span id="inside_dia_top" class="orage"></span></div><div style="width: 100%" class="filter_dimensions_part"><span id="t_height"></span>: <span id="filter_height" class="orage"></span></div><div style="width: 100%" class="filter_dimensions_part"><span id="t_thread_size"></span>: <span id="filter_thread_size" class="orage"></span></div></div><div style="float: left; clear: both;"><div class="filter_dotted">.........................................</div><div class="filter_args_line"><span id="t_filter_style"></span>: <span id="filter_style" class="orage"></span></div><div class="filter_args_line"><span id="t_filter_type"></span>: <span id="filter_type" class="orage"></span></div><div class="filter_args_line"><span id="t_filter_media"></span>: <span id="filter_media" class="orage"></span></div><div class="filter_args_line"><span id="t_filter_service"></span>: <span id="filter_service" class="orage"></span></div><div id="t_applications" class="filter_args_line">:</div><div class="filter_args_line"><span id="t_applications_value" class="orage"></span></div><div class="filter_dotted">.........................................</div></div></div>';
}

var filtronFilterContent = function() {
	return '<div class="filter_title"><span id="t_filter"></span> <span id="t_filter_number" class="orage"></span></div><div class="filter_dotted">.........................................</div><div class="filter_image_cnt"><div class="filter_image"><a class="largeFilterImage" href="" rel="lightbox" title=""><img id="smallFilterImage" src=""/></a></div><a href="" rel="lightbox" id="t_zoom" class="largeFilterImage filter_zoom"></a></div><div id="t_dimension" class="filter_dimensions_title"></div><div class="filter_dimensions_line"><div class="filter_dimensions_first_part">A: <span id="t_dim_a" class="orage"></span></div><div class="filter_dimensions_part">B: <span id="t_dim_b" class="orage"></span></div></div><div class="filter_dimensions_line"><div class="filter_dimensions_first_part">C: <span id="t_dim_c" class="orage"></span></div><div class="filter_dimensions_part">D: <span id="t_dim_d"class="orage"></span></div></div><div class="filter_dimensions_line"><div class="filter_dimensions_first_part">E: <span id="t_dim_e" class="orage"></span></div><div class="filter_dimensions_part">F: <span id="t_dim_f" class="orage"></span></div></div><div class="filter_dimensions_line"><div class="filter_dimensions_first_part">G: <span id="t_dim_g" class="orage"></span></div><div class="filter_dimensions_part">H: <span id="t_dim_h" class="orage"></span></div></div><div class="filter_dotted">.........................................</div><div class="filter_args_line"><span id="t_by_pass_valve"></span>: <span id="t_by_pass_valve_value" class="orage"></span></div><div class="filter_args_line"><span id="t_anti_drain_valve"></span>: <span id="t_anti_drain_valve_value" class="orage"></span></div><div class="filter_args_line"><span id="t_anti_syphon_valve"></span>: <span id="t_anti_syphon_valve_value" class="orage"></span></div><div id="t_applications" class="filter_args_line">:</div><div class="filter_args_line"><span id="t_applications_value" class="orage"></span></div><div class="filter_dotted">.........................................</div>';
}
